/*
 * 06数组名作为函数参数.c
 *
 *  Created on: 2024年3月9日
 *      Author: HP
 */
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<time.h>

void my_strcat(char* ch1, char* ch2){
	int i = 0;
	while(ch1[i] != '\0'){
		i++;
	}
	printf("%d\n", i);
	printf("%d\n", strlen(ch1));

	int j = 0;
	while(ch2[j] != '\0'){
		ch1[i+j] =ch2[j];
		j++;
	}
	ch1[i+j] = '\0';
}

void my_strcat2(char* ch1, char* ch2){
	int i = 0;
	while(*(ch1+i) != '\0'){
		i++;
	}

	int j = 0;
	while(*(ch2+j) != '\0'){
		*(ch1+i+j) = *(ch2+j);
		j++;
	}
	*(ch1+i+j) = '\0';
}

void my_strcat3(char* ch1, char* ch2){
	while(*ch1)ch1++;
	while(*ch2){
		*ch1 = *ch2;
		ch1++;
		ch2++;
	}
}

void my_strcat4(char* ch1, char* ch2){
	while(*ch1)ch1++;
	while(*ch1++ = *ch2++);
}

void remove_space(char* ch){
	// 用来遍历字符串
	char* ftemp = ch;
	// 记录非空格字符串
	char* rtemp = ch;
	while(*ftemp){ // ftemp != '\0'
		if(*ftemp != ' '){
			*rtemp = *ftemp;
			rtemp++;
		}
		ftemp++;
	}
	*rtemp = 0;
}

int main0606(void){
	char ch1[100] = "hello";
	char ch2[] = "world";
	my_strcat4(ch1, ch2);
	printf("%s\n", ch1);

	char ch[] = "   h e ll o wor ld";
	remove_space(ch);
	printf("%s\n", ch);
	return 0;
}
